﻿using ConsoleTables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Collections.Specialized;

namespace LimsFormRequest
{
    class Program
    {
        /// <summary>
        /// 美信查询委托单接口
        /// </summary>
        static void test3()
        {
            string baseUrl = "http://localhost:8001";
            // http post 请求
            string tokenUrl = baseUrl+"/LIMS-Server/MPLM_Service_Gateway/TokenGenerator/getToken";
            string url = baseUrl+"/LIMS-Server/MPLM_Service_Gateway/MeixinTestFormController/searchTestFormList";


            string name = "ex_dengcc2";
            string funcName = "getForm";
            //string data = "equipmentNumber=A2202020122200001222&ipAddr=10.52.21.36&port=9090&blockName=RAC&bsType=RAC_1&protocol=http";

            NameValueCollection postData = new NameValueCollection();
            postData.Add("userName", "ex_dengcc2");
            postData.Add("orgType", "BusinessUnit");
            postData.Add("pageIndex", "1");
            postData.Add("pageSize", "10");
            postData.Add("TestFormType", "WholeEngineForm");
            postData.Add("createTime", "%5B%222023-6-21%22%2C%222023-7-21%22%5D");
            postData.Add("testFormNumber", "");
            postData.Add("projectNumber", "");
            postData.Add("consigner", "ex_wangli32");
            postData.Add("buId", "14");
            string v2 = MyTools.RestfullRequest.LimsPostFormUseToken(tokenUrl, url, name, funcName, postData);
            Console.WriteLine(v2);

        }


        static void Main(string[] args)
        {
            //test2();

            test3();

            Console.ReadKey();
        }

        static void test2()
        {
            // http post 请求
            string tokenUrl = "https://limsuat.midea.com/LIMS-Server/MPLM_Service_Gateway/TokenGenerator/getToken";
            string url = "https://limsuat.midea.com/LIMS-Server/MPLM_Service_Gateway/raclimsRestfulController/updateEquipmentIp";
            string name = "ex_cuiml1";
            string funcName = "getForm";
            string data = "equipmentNumber=A2202020122200001222&ipAddr=10.52.21.36&port=9090&blockName=RAC&bsType=RAC_1&protocol=http";
            string v2 = MyTools.RestfullRequest.LimsPostFormUseToken(tokenUrl, url, name, funcName, data);
            //Console.WriteLine(v2);

            Root root = JsonConvert.DeserializeObject<Root>(v2);

            var table = new ConsoleTable("one", "two", "three");
            table.AddRow(1, 2, 3)
                 .AddRow(root.message, root.status, root.data.msg);

            table.Write();
            Console.WriteLine();

        }
    }

    public class Root
    {
        public string message { get; set; }
        public string messageType { get; set; }
        public string status { get; set; }
        public Data data { get; set; }
    }

    public class Data
    {
        public string msg { get; set; }
        public Boolean success { get; set; }
    }
}
